package jmine.tec.security.permission;

import javax.security.auth.Subject;

import bancosys.tec.security.SecurityService;
import bancosys.tec.security.authorization.Permission;

/**
 * Implementacao trivial de {@link PermissionChecker} que usa o {@link SecurityService} para determinar se o subject passado tem ou nao
 * permissao para determinado recurso
 * 
 * @author takeshi
 */
public class PermissionCheckerImpl implements PermissionChecker {
    private final String permissionId;

    private final Class<? extends Permission> type;

    private final SecurityService securityService;

    /**
     * @param service the {@link SecurityService}
     * @param permissionId {@link String} com o permission id
     * @param type {@link Class}
     */
    public PermissionCheckerImpl(SecurityService service, String permissionId, Class<? extends Permission> type) {
        this.permissionId = permissionId;
        this.type = type;
        this.securityService = service;
    }

    /**
     * {@inheritDoc}
     */
    public boolean hasPermission(Subject subject) {
        return securityService.hasPermission(subject, type, permissionId);
    }
}